package tests;

import Common.Utils;
import org.openqa.selenium.By;

import java.io.IOException;

public class loginPage extends Utils {
    public static String url = "http://localhost:8080/user/login";
    public loginPage() {
        super(url);
    }
    //检查页面是否加载成功
    public void loginPageRight() {
        //通过查看页面元素是否存在来检查页面加载成功与否
        driver.findElement(By.cssSelector("#userLoginPage > h2"));
        //登陆输入框
        driver.findElement(By.cssSelector("#userLoginPage > form > div:nth-child(3) > div.arco-col.arco-form-item-wrapper-col > div > div > div > button"));
    }

    //检查登录功能---成功登录
    public void LoginSuc() throws IOException, InterruptedException {
        driver.navigate().refresh();
        driver.findElement(By.cssSelector("#userAccount > div > div > span > input")).clear();
        driver.findElement(By.cssSelector("#userAccount > div > div > span > input")).sendKeys("wanghui");
        driver.findElement(By.cssSelector("#userPassword > div > div > span > input")).clear();
        driver.findElement(By.cssSelector("#userPassword > div > div > span > input")).sendKeys("12345678");
        driver.findElement(By.cssSelector("#userLoginPage > form > div:nth-child(3) > div.arco-col.arco-form-item-wrapper-col > div > div > div > button")).click();
        String currentUrl = driver.getCurrentUrl();
        assert "http://localhost:8080/".equals(currentUrl);
        Thread.sleep(2000);
//        getScreenShot(this.getClass().getName());
    }

    //检查登录功能---登录失败(用户名错误密码正确)
    public void LoginFail1() throws InterruptedException, IOException {
        driver.navigate().refresh();
        driver.findElement(By.cssSelector("#userAccount > div > div > span > input")).clear();
        driver.findElement(By.cssSelector("#userAccount > div > div > span > input")).sendKeys("wanghui12345678");
        driver.findElement(By.cssSelector("#userPassword > div > div > span > input")).clear();
        driver.findElement(By.cssSelector("#userPassword > div > div > span > input")).sendKeys("12345678");
        driver.findElement(By.cssSelector("#userLoginPage > form > div:nth-child(3) > div.arco-col.arco-form-item-wrapper-col > div > div > div > button")).click();
        String currentUrl = driver.getCurrentUrl();
        assert url.equals(currentUrl);
        Thread.sleep(2000);
//        getScreenShot(this.getClass().getName());
    }
    //检查登录功能---登录失败(用户名正确密码错误)
    public void LoginFail2() throws InterruptedException, IOException {
        driver.navigate().refresh();
        driver.findElement(By.cssSelector("#userAccount > div > div > span > input")).clear();
        driver.findElement(By.cssSelector("#userAccount > div > div > span > input")).sendKeys("wanghui");
        driver.findElement(By.cssSelector("#userPassword > div > div > span > input")).clear();
        driver.findElement(By.cssSelector("#userPassword > div > div > span > input")).sendKeys("12345678910");
        driver.findElement(By.cssSelector("#userLoginPage > form > div:nth-child(3) > div.arco-col.arco-form-item-wrapper-col > div > div > div > button")).click();
        String currentUrl = driver.getCurrentUrl();
        assert url.equals(currentUrl);
        Thread.sleep(2000);
//        getScreenShot(this.getClass().getName());
    }

    //检查登录功能---登录失败(用户名空密码正确)
    public void LoginFail3() throws InterruptedException, IOException {
        driver.navigate().refresh();
        driver.findElement(By.cssSelector("#userAccount > div > div > span > input")).clear();
        driver.findElement(By.cssSelector("#userPassword > div > div > span > input")).clear();
        driver.findElement(By.cssSelector("#userPassword > div > div > span > input")).sendKeys("12345678");
        driver.findElement(By.cssSelector("#userLoginPage > form > div:nth-child(3) > div.arco-col.arco-form-item-wrapper-col > div > div > div > button")).click();
        String currentUrl = driver.getCurrentUrl();
        assert url.equals(currentUrl);
        Thread.sleep(2000);
//        getScreenShot(this.getClass().getName());
    }
    //检查登录功能---登录失败(用户名正确密码空)
    public void LoginFail4() throws InterruptedException, IOException {
        driver.navigate().refresh();
        driver.findElement(By.cssSelector("#userAccount > div > div > span > input")).clear();
        driver.findElement(By.cssSelector("#userAccount > div > div > span > input")).sendKeys("wanghui");
        driver.findElement(By.cssSelector("#userPassword > div > div > span > input")).clear();
        driver.findElement(By.cssSelector("#userLoginPage > form > div:nth-child(3) > div.arco-col.arco-form-item-wrapper-col > div > div > div > button")).click();
        String currentUrl = driver.getCurrentUrl();
        assert url.equals(currentUrl);
        Thread.sleep(2000);
//        getScreenShot(this.getClass().getName());
    }
}
